【Cocos2d

您所在的位置:网站首页 cocos2dx json解密 【Cocos2d

【Cocos2d

2024-07-16 07:06| 来源: 网络整理| 查看: 265

加密就不用说了,看上一篇2.X加密的方式,怎么弄都可以。的保证解密规则就行; 原文:http://www.cnblogs.com/zisou/p/cocos2d-xjm.html 现在重点说3.X解密: 在新的3.X引擎中官方整合了大部分获取资源的方法,最终合成一个getdata; 可以从源码,和堆栈调用中看到: CCFileUtils.cpp: Data FileUtils::getDataFromFile(const std::string& filename){ return getData(filename, false);} getDataFromFile目前只调用getData(filename,false); Data getData(const std::string& filename, bool forString) 这个函数是一个非类成员静态函数。 forString是用来标识是否是一个文本文件,如果是那么buffer需要多一个字节。 这个其实不重要,因为我们处理的最终buffer是获取完全的 所以直接改代码: static Data getData(const std::string& filename, bool forString){ if (filename.empty()) { return Data::Null; } Data ret; unsigned char* buffer = nullptr; size_t size = 0; size_t readsize; const char* mode = nullptr; if (forString) mode = “rt”; else mode = “rb”; std::string lastname = FileUtils::getInstance()->fullPathForFilename(filename); lastname = lastname.substr(lastname.length()-5,lastname.length()); do { // Read the file from hardware std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename); FILE fp = fopen(fullPath.c_str(), mode); CC_BREAK_IF(!fp); fseek(fp,0,SEEK_END); size = ftell(fp); fseek(fp,0,SEEK_SET); if (forString) { buffer = (unsigned char)malloc(sizeof(unsigned char) * (size + 1)); buffer = ‘\0’; } else { buffer = (unsigned char*)malloc(sizeof(unsigned char) * size); } readsize = fread(buffer, sizeof(unsigned char), size, fp); fclose(fp); if (forString && readsize < size) { buffer = ‘\0’; } } while (0); if (nullptr == buffer || 0 == readsize) { std::string msg = “Get data from file(”; msg.append(filename).append(") failed!"); CCLOG("%s", msg.c_str()); } else { if(lastname == “_jm.d”) { for (int i = 0; i %s”,byteCodePath.c_str()); if (futil->isFileExist(byteCodePath)) { Data data = futil->getDataFromFile(byteCodePath); if (!data.isNull()) { script = JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr, nullptr); } } Data data = futil->getDataFromFile(byteCodePath); 对于脚本语言的加载读取还是上面我们已经改过的getDataFromFile方法噢! 但是还有一点 script = JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr, nullptr); 这样是直接拿不到script的,JS_DecodeScript只是处理.jsc的,那么怎么给script复制呢? 代码修改如下: //只解密scr下面目录文件 if(jmflag==true) { if (futil->isFileExist(jmfullPath)) { Data data = futil->getDataFromFile(jmfullPath,true); if (!data.isNull()) { script = JS::Compile(cx, obj, options, (const char*)data.getBytes(), data.getSize()); } } } else { script = JS::Compile(cx, obj, options, fullPath.c_str()); } script = JS::Compile(cx, obj, options, (const char*)data.getBytes(), data.getSize()); 用Compile的这个重载函数赋值就全部搞定了;Lua和JS的脚本代码解密也一样非常简单! 大功告成,再见!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3